<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$dsn = "mysql:dbname=cnrt;host=127.0.0.1";
$user = "ragnarok";
$pass = 'clave';
try {
  $conn = new PDO($dsn, $user, $pass);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $resultado = $conn->query('SELECT * FROM personas');
} catch (Exception $e) {
  echo "Este programa no funciona: " . $e->getMessage();
}
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=archivo.xls");
header("Pragma: no-cache");
header("Expires: 0");
?>
<html>
  <body>
    <table border="1">
      <thead>
        <tr>
          <th>id</th>
          <th>apellido</th>
          <th>nombre</th>
          <th>email</th>
        </tr>
      </thead>
      <?php foreach ($resultado as $registro): ?>
        <tr>
          <td><font color="#ff0000"><?php echo $registro['id'] ?></font></td>
          <?php echo "<td>" .$registro['apellido'] . "</td>"?>
          <td><?php echo $registro['nombre'] ?></td>
          <td><?php echo $registro['email'] ?></td>
        </tr>
      <?php endforeach; ?>
    </table>
  </body>
</html>
